package com.example.cr.insect.controller.admin;

import com.example.cr.common.response.PageResponse;
import com.example.cr.common.response.R;
import com.example.cr.insect.request.PestIdentificationListRequest;
import com.example.cr.insect.response.PestIdentificationResponse;
import com.example.cr.insect.service.PestIdentificationService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.cr.insect.request.PestIdentificationRequest;
import java.util.List;

@RestController
@RequestMapping("admin/pest-identification")
public class PestIdentificationAdminController {
    @Autowired
    PestIdentificationService pestIdentificationService;

    @GetMapping("list")
    public R<PageResponse<PestIdentificationResponse>> list(@Valid PestIdentificationListRequest request) {
        PageResponse<PestIdentificationResponse> list = pestIdentificationService.list(request);
        return R.ok(list);
    }
    @PostMapping("save")
    public R<Object> save(@Valid @RequestBody PestIdentificationRequest request) {
        pestIdentificationService.save(request);
        return R.ok();
    }

    @DeleteMapping("delete")
    public R<Integer> delete(@RequestBody List<Long> ids) {
        int result = pestIdentificationService.deleteBatch(ids);
        return R.ok(result);
    }
}
